package com.imti.controller;

import com.imti.bean.DeskInfo;
import com.imti.bean.GroupInfo;
import com.imti.bean.Nurse;
import com.imti.service.NuresService;
import com.imti.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/nurse")
public class NurseController {

    @Autowired
    private NuresService nuresService;

    @RequestMapping("/page")
    public String findAllDoc(Nurse nurse, PageBean page, HttpServletRequest request) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("nurse", nurse);
        map.put("page", page);
        PageBean p = nuresService.pageNurse(map);
        request.setAttribute("page", p);
        return "/nurse-list";
    }
    /*添加页面跳转*/
    @RequestMapping("/addNurse")
    public String addNurse(HttpServletRequest request){
        List<DeskInfo> DeskList = nuresService.findAllDesk();
        request.setAttribute("DeskList", DeskList);
        return "nurse-add";
    }
    /*增加护士数据*/
    @RequestMapping("/saveNurse")
    @ResponseBody
    public String saveNurse(Nurse nurse,HttpServletRequest request){
        int res = nuresService.insert(nurse);
        return "redirect:/role/page?res=" + res;
        /*return "res";*/
    }

    /*验证是否存在*/
    @RequestMapping("/getCountOne")
    @ResponseBody
    public String selectOne(Nurse nurse) {
        int res = nuresService.selectCountOne(nurse);
        return res > 0 ? "1" : "0";
    }


    /*修改'1 在职 0离职  2开除 3退休',*/
    @RequestMapping("/updateNurseState")
    @ResponseBody
    public String updateNurse(Nurse nurse){
        int res = nuresService.update(nurse);
        return res > 0 ? "1" : "0";
    }
}
